package com.brtbeacon.wx.demo.mapview;

import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.widget.Toast;

import com.brtbeacon.wx.map.BRTMapWebViewActivity;

import java.util.Calendar;

public class MapWebViewActivity extends BRTMapWebViewActivity {

    public static void startActivity(Context ctxt, String url) {
        Intent intent = new Intent(ctxt, MapWebViewActivity.class);
        intent.putExtra(PARAM_URL, url);
        ctxt.startActivity(intent);
    }

    private long lastKeyBackTimeMillis = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {

            if(webView.canGoBack()) {
                webView.goBack();
                return true;
            }

            long keyBackTimeMillis = Calendar.getInstance().getTimeInMillis();
            if (keyBackTimeMillis - lastKeyBackTimeMillis >= 1000) {
                Toast.makeText(this, "再按一次返回，退出地图演示!", Toast.LENGTH_SHORT).show();
                lastKeyBackTimeMillis = keyBackTimeMillis;
            } else {
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
